<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-20
 * Func   彩票期号
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$table = Table('lottery_period');
$ctable = Table('lottery');

if($a == 'del')
{
	$id = intval($_GET['id']);
	$flag = $_GET['flag'] ? 1 : 0;
	
    $id && $db->exec('DELETE FROM '.$table.' WHERE id = '.$id);
	
	ShowMsg('操作成功',-1);
}
else
{
	//	彩票种类
	$lottery = $db->getall('SELECT id,title,credit FROM '.Table('lottery').' WHERE status = 1 ORDER BY id','id');
	
	//	状态
	$statuss = ['未开始','已开始','开奖中','已开奖'];

    $data  = array();
    $where = ' FROM '.$table.' t WHERE 1 ';
	
	$cid = intval($_GET['cid']);
	if(!$cid)
	{
		$tmp = $lottery;
		$tmp = array_shift($tmp);
		$cid = $tmp['id'];
	}
	$where .= ' AND t.cid = '.$cid;
	
	$title = NoBadStr($_GET['title']);
	$title && $where .= ' AND t.period LIKE \'%'.$title.'%\' ';

    $tmp = $db->getrow('SELECT COUNT(1) AS p '.$where);
    if($tmp['p'])
	{
        $page = max(1,intval($_GET['page']));
        $size = 20;
        $limit    = ' LIMIT '.($page - 1) * $size.','.$size;

        $orderby = ' ORDER BY t.dateline DESC ';
        $url = '?m='.$m.'&c='.$c.'&a='.$a;
		
        $data = $db->getall('SELECT t.* '.$where.$orderby.$limit);
        
		$multi = Multi($url,$page,$tmp['p'],$size);
    }

    $tpl->display($m.'/period');
}